import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 访问类型枚举 */
export enum AccessTypeEnum {
  /** 匿名访问 */
  Anonymous = 1,
  /** 登录访问 */
  LoggedIn = 2,
  /** 角色访问 */
  RoleLimit = 3,
}

/** 访问类型实体 */
export class AccessTypeEntity {
  /** 访问类型 */
  AccessType: AccessTypeEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(accessType: AccessTypeEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.AccessType = accessType;
    this.Color = color;
    switch (accessType) {
      case AccessTypeEnum.Anonymous:
        // this.Display = '匿名访问';
        this.Display = t('enum.accessType.anonymous');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case AccessTypeEnum.LoggedIn:
        // this.Display = '登录访问';
        this.Display = t('enum.accessType.loggedIn');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case AccessTypeEnum.RoleLimit:
        // this.Display = '角色访问';
        this.Display = t('enum.accessType.roleLimit');
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
    }
  }
}

//#region 获取访问类型枚举架构
/**
 * 获取访问类型枚举架构
 */
export function getAccessTypeEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: AccessTypeEntity[] = [
    new AccessTypeEntity(AccessTypeEnum.Anonymous),
    new AccessTypeEntity(AccessTypeEnum.LoggedIn),
    new AccessTypeEntity(AccessTypeEnum.RoleLimit),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.AccessType as number,
      label: item.Display,
      value: item.AccessType as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
